package com.ruoyi.currency.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.currency.domain.TbCurrency;
import com.ruoyi.currency.service.ITbCurrencyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 币别Controller
 * 
 * @author 刘凯豪
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/currency/currency")
public class TbCurrencyController extends BaseController
{
    @Autowired
    private ITbCurrencyService tbCurrencyService;

    /**
     * 查询币别列表
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCurrency tbCurrency)
    {
        startPage();
        List<TbCurrency> list = tbCurrencyService.selectTbCurrencyList(tbCurrency);
        return getDataTable(list);
    }

    /**
     * 导出币别列表
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:export')")
    @Log(title = "币别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCurrency tbCurrency)
    {
        List<TbCurrency> list = tbCurrencyService.selectTbCurrencyList(tbCurrency);
        ExcelUtil<TbCurrency> util = new ExcelUtil<TbCurrency>(TbCurrency.class);
        util.exportExcel(response, list, "币别数据");
    }

    /**
     * 获取币别详细信息
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:query')")
    @GetMapping(value = "/{currencyId}")
    public AjaxResult getInfo(@PathVariable("currencyId") Long currencyId)
    {
        return success(tbCurrencyService.selectTbCurrencyByCurrencyId(currencyId));
    }

    /**
     * 新增币别
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:add')")
    @Log(title = "币别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCurrency tbCurrency)
    {
        return toAjax(tbCurrencyService.insertTbCurrency(tbCurrency));
    }

    /**
     * 修改币别
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:edit')")
    @Log(title = "币别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCurrency tbCurrency)
    {
        return toAjax(tbCurrencyService.updateTbCurrency(tbCurrency));
    }

    /**
     * 删除币别
     */
    @PreAuthorize("@ss.hasPermi('currency:currency:remove')")
    @Log(title = "币别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{currencyIds}")
    public AjaxResult remove(@PathVariable Long[] currencyIds)
    {
        return toAjax(tbCurrencyService.deleteTbCurrencyByCurrencyIds(currencyIds));
    }
}
